// 灰度发布配置

module.exports = {
  // 灰度发布策略
  strategy: {
    type: process.env.GRAY_RELEASE_TYPE || 'percentage', // percentage, whitelist, region
    percentage: parseInt(process.env.GRAY_RELEASE_PERCENTAGE) || 10, // 10%
    maxUsers: parseInt(process.env.GRAY_RELEASE_MAX_USERS) || 1000,
    duration: parseInt(process.env.GRAY_RELEASE_DURATION) || 7 * 24 * 60 * 60 * 1000 // 7天
  },

  // 灰度用户白名单
  whitelist: {
    enabled: process.env.GRAY_WHITELIST_ENABLED === 'true',
    users: (process.env.GRAY_WHITELIST_USERS || '').split(',').filter(Boolean),
    phones: (process.env.GRAY_WHITELIST_PHONES || '').split(',').filter(Boolean),
    openids: (process.env.GRAY_WHITELIST_OPENIDS || '').split(',').filter(Boolean)
  },

  // 地区限制
  regions: {
    enabled: process.env.GRAY_REGIONS_ENABLED === 'true',
    allowed: (process.env.GRAY_ALLOWED_REGIONS || '').split(',').filter(Boolean),
    blocked: (process.env.GRAY_BLOCKED_REGIONS || '').split(',').filter(Boolean)
  },

  // 功能开关
  features: {
    // 新功能开关
    newAdSystem: {
      enabled: process.env.FEATURE_NEW_AD_SYSTEM === 'true',
      percentage: parseInt(process.env.FEATURE_NEW_AD_SYSTEM_PERCENTAGE) || 0
    },
    
    enhancedPoints: {
      enabled: process.env.FEATURE_ENHANCED_POINTS === 'true',
      percentage: parseInt(process.env.FEATURE_ENHANCED_POINTS_PERCENTAGE) || 0
    },
    
    newUI: {
      enabled: process.env.FEATURE_NEW_UI === 'true',
      percentage: parseInt(process.env.FEATURE_NEW_UI_PERCENTAGE) || 0
    }
  },

  // 监控配置
  monitoring: {
    enabled: true,
    metrics: {
      errorRate: true,
      responseTime: true,
      userFeedback: true,
      businessMetrics: true
    },
    
    // 自动回滚条件
    autoRollback: {
      enabled: process.env.GRAY_AUTO_ROLLBACK === 'true',
      errorRateThreshold: parseFloat(process.env.GRAY_ERROR_RATE_THRESHOLD) || 0.05, // 5%
      responseTimeThreshold: parseInt(process.env.GRAY_RESPONSE_TIME_THRESHOLD) || 2000, // 2秒
      userComplaintThreshold: parseInt(process.env.GRAY_COMPLAINT_THRESHOLD) || 10
    }
  },

  // 数据收集
  dataCollection: {
    enabled: true,
    
    // 用户行为数据
    userBehavior: {
      pageViews: true,
      clicks: true,
      adViews: true,
      conversions: true,
      retention: true
    },
    
    // 性能数据
    performance: {
      loadTime: true,
      apiResponseTime: true,
      errorLogs: true
    },
    
    // 业务数据
    business: {
      registrations: true,
      pointsEarned: true,
      pointsSpent: true,
      orders: true,
      revenue: true
    }
  }
};